﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Vtron.HipcConfigurationTools.Core;
using Vtron.HipcConfigurationTools.Domain;

namespace Vtron.HipcConfigurationTools.Test
{
    /// <summary>
    /// 解码盒API接口测试
    /// </summary>
    [TestClass]
    public class DecodedAPIUnitTest
    {
        [TestInitialize]
        public void Init()
        {
            Utils.IP = "10.4.1.173";
            Utils.PORT = 5001;
        }

        /// <summary>
        /// 消息		视频连接请求
        /// ID(msgType)	请求：0x8001  应答：0x8002
        /// 方向	VWAS->解码盒                                                
        /// 参数	typedef struct 
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Int8   mode;//暂无定义
        ///     Int8   dispID; //显示窗口ID(解码端)
        ///     Int8   srcIP[20]; //源IP地址(编码端)
        ///     UInt32 srcChannel; //通道号(编码端)
        ///     /*Uint16   width;*/
        ///     /*Uint16   height;*/
        /// }T_HIPC_VWAS_DEC_VIDEO_CONNECT_REQ, T_HIPC_VWAS_DEC_VIDEO_CONNECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VWAS_DEC_VIDEO_CONNECT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VWAS_DEC_VIDEO_CONNECT_REQ request = new T_HIPC_VWAS_DEC_VIDEO_CONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8001 };
            T_HIPC_VWAS_DEC_VIDEO_CONNECT_RESP response = handler.Handle<T_HIPC_VWAS_DEC_VIDEO_CONNECT_RESP>(request);

            Assert.AreEqual(0x8002, response.head.msgType);
        }

        /// <summary>
        /// 消息		视频连接断开
        /// ID(msgType)	请求：0x8003      应答: 0x8004
        /// 方向	VWAS->解码盒                                                
        /// 参数	typedef struct 
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///    Int8   dispID; //显示窗口ID(解码端)
        /// }T_HIPC_VWAS_DEC_VIDEO_DISCONNECT_REQ, T_HIPC_VWAS_DEC_VIDEO_DISCONNECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VWAS_DEC_VIDEO_DISCONNECT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VWAS_DEC_VIDEO_DISCONNECT_REQ request = new T_HIPC_VWAS_DEC_VIDEO_DISCONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8003 };
            T_HIPC_VWAS_DEC_VIDEO_DISCONNECT_RESP response = handler.Handle<T_HIPC_VWAS_DEC_VIDEO_DISCONNECT_RESP>(request);

            Assert.AreEqual(0x8004, response.head.msgType);
        }

        /// <summary>
        /// 消息		音频连接请求
        /// ID(msgType)	请求：0x8005  应答：0x8006
        /// 方向	VWAS->解码盒                                                
        /// 参数	typedef struct 
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Int8   mode;//暂无定义
        ///     Int8   playID; //音频播放ID(解码端)
        ///     Int8   srcIP[20]; //源IP地址(编码端)
        ///     UInt32 srcChannel; //通道号(编码端)
        /// } T_HIPC_VWAS_DEC_AUDIO_CONNECT_REQ, T_HIPC_VWAS_DEC_AUDIO_CONNECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VWAS_DEC_AUDIO_CONNECT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VWAS_DEC_AUDIO_CONNECT_REQ request = new T_HIPC_VWAS_DEC_AUDIO_CONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8005 };
            T_HIPC_VWAS_DEC_AUDIO_CONNECT_RESP response = handler.Handle<T_HIPC_VWAS_DEC_AUDIO_CONNECT_RESP>(request);

            Assert.AreEqual(0x8006, response.head.msgType);
        }

        /// <summary>
        /// 消息		音频连接断开
        /// ID(msgType)	请求：0x8007      应答: 0x8008
        /// 方向	VWAS->解码盒                                                
        /// 参数	typedef struct 
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Int8   playID; //音频播放ID(解码端)
        /// } T_HIPC_VWAS_DEC_AUDIO_DISCONNECT_REQ, T_HIPC_VWAS_DEC_AUDIO_DISCONNECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VWAS_DEC_AUDIO_DISCONNECT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VWAS_DEC_AUDIO_DISCONNECT_REQ request = new T_HIPC_VWAS_DEC_AUDIO_DISCONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8007 };
            T_HIPC_VWAS_DEC_AUDIO_DISCONNECT_RESP response = handler.Handle<T_HIPC_VWAS_DEC_AUDIO_DISCONNECT_RESP>(request);

            Assert.AreEqual(0x8008, response.head.msgType);
        }

        /// <summary>
        /// 消息		KVM连接请求
        /// ID(msgType)	请求：0x8009  应答：0x800a
        /// 方向	VWAS->解码盒                                                
        /// 参数	typedef struct 
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Int8   srcIP[20]; //源IP地址(编码端)
        /// } T_HIPC_VWAS_DEC_KVM_CONNECT_REQ, T_HIPC_VWAS_DEC_KVM_CONNECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VWAS_DEC_KVM_CONNECT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VWAS_DEC_KVM_CONNECT_REQ request = new T_HIPC_VWAS_DEC_KVM_CONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8009 };
            T_HIPC_VWAS_DEC_KVM_CONNECT_RESP response = handler.Handle<T_HIPC_VWAS_DEC_KVM_CONNECT_RESP>(request);

            Assert.AreEqual(0x800a, response.head.msgType);
        }

        /// <summary>
        /// 消息		KVM连接断开
        /// ID(msgType)	请求：0x800b      应答: 0x800c
        /// 方向	VWAS->解码盒                                                
        /// 参数	typedef struct 
        /// {
        ///     T_HIPC_NET_HEADER	   head;	   
        /// } T_HIPC_VWAS_DEC_KVM_DISCONNECT_REQ, T_HIPC_VWAS_DEC_KVM_DISCONNECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VWAS_DEC_KVM_DISCONNECT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VWAS_DEC_KVM_DISCONNECT_REQ request = new T_HIPC_VWAS_DEC_KVM_DISCONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x800b };
            T_HIPC_VWAS_DEC_KVM_DISCONNECT_RESP response = handler.Handle<T_HIPC_VWAS_DEC_KVM_DISCONNECT_RESP>(request);

            Assert.AreEqual(0x800c, response.head.msgType);
        }

        /// <summary>
        /// 消息		查询解码端连接状态
        /// ID(msgType)	请求：0x800d  应答：0x800e
        /// 方向	VWAS->解码盒                                                
        /// 参数	typedef struct 
        /// {
         ///    Int8 ipaddr[16]; //源IP地址
         ///    Int8 channel; //通道号
        ///     Int8 type; //0:video-connect  ,1:audio-connect  ,2:kvm-connect   
        /// }DEC_CONNECT_STATUS;
        /// typedef struct 
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        /// }T_HIPC_VWAS_DEC_CONNECT_STATUS_REQ;
        /// typedef struct 
        /// {
         ///    T_HIPC_NET_HEADER	   head;
        ///     Int8   count;//解码端连接计数
        /// 	DEC_CONNECT_STATUS connectEnc[50];//连接信息
        /// }T_HIPC_VWAS_DEC_CONNECT_STATUS_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VWAS_DEC_CONNECT_STATUS_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VWAS_DEC_CONNECT_STATUS_REQ request = new T_HIPC_VWAS_DEC_CONNECT_STATUS_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x800d };
            T_HIPC_VWAS_DEC_CONNECT_STATUS_RESP response = handler.Handle<T_HIPC_VWAS_DEC_CONNECT_STATUS_RESP>(request);

            Assert.AreEqual(0x800e, response.head.msgType);
        }
    }
}
